#ifndef _UTIL_H_
#define _UTIL_H_
#include "dataShare/Configuration.h"
#include "iec61850_model.h"

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ptree_fwd.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
#include <memory>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
#include <zlog.h>

#define zlog_i(...) zlog_info(Util::log, __VA_ARGS__)
#define zlog_n(...) zlog_notice(Util::log, __VA_ARGS__)
#define zlog_w(...) zlog_warn(Util::log, __VA_ARGS__)
#define zlog_e(...) zlog_error(Util::log, __VA_ARGS__)
#define ZLOG_CAT_NAME "datalink_app_mms"
#define ZLOG_LOG_PAHT "/usr/local/logs/zlog_archive"

struct ErrorInfo {
    static const int OK                    = 0;
    static const int REDIS_CONNECT         = 1;  // redis 连接错误
    static const int REDIS_OFFLINE         = 2;  // redis offline
    static const int REDIS_OVERTIME        = 3;  // 等待超时
    static const int DATA_NULL             = 4;  // 数据长度为0
    static const int UPLOAD_FAIL           = 5;
    static const int REDIS_STREAM_RECV     = 6;  //  recvstream fail
    static const int REDIS_QUERY_FAIL      = 7;  // Query fail
    static const int REDIS_STREAM_SEND     = 8;  // send stream fail
    static const int EMPTY_DATA            = 9;
    static const int CONFIG_FILE_NOT_FOUND = 10; // 配置文件未找到
    static const int CONFIG_FILE_FAIL      = 11; // 配置集群数量不足
    static const int ZLOG_INIT_FAIL        = 11; // zlog初始化失败
    static const int UNKNOW_ERR            = 99; // 未知错误
};

class Util {
  public:
    Util();
    virtual ~Util();

    static void Uninstall();
    static int  Init();

    static int LoadConfiguration();

    static bool isFileExist(const std::string &name);

    static long long TimeStamp();

    static std::string GetVarName(ModelNode *attr);

    std::string GetDevName(ModelNode *node);

    std::string GetDoName(ModelNode *node);

    static std::shared_ptr<Util> GetInstance();

  private:
    static int                   rc;
    static std::shared_ptr<Util> util;

  public:
    static zlog_category_t *log;
};

#endif // !_UTIL_H_
